package com.axend.aerosense.room.ui.adapter;

import com.axend.aerosense.common.adapter.BaseBindingAdapter;
import com.axend.aerosense.room.R;
import com.axend.aerosense.room.databinding.RoomLayoutEditItemBinding;
import com.axend.aerosense.room.entity.RoomEditListBean;
import com.axend.aerosense.room.entity.RoomSortInfoBean;

import java.util.Collections;
import java.util.List;

public class RoomEditTouchAdapter
        extends BaseBindingAdapter<RoomSortInfoBean, RoomLayoutEditItemBinding> {

    private OnClickListener onClickListener;

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.room_layout_edit_item;
    }

    @Override
    protected void onBindItem(RoomLayoutEditItemBinding binding, RoomSortInfoBean item, int position) {
        binding.roomName.setText(item.getRoomName());
        binding.roomDeviceCount.setText(String.format(binding.roomDeviceCount.getText().toString(), item.getRadarCount()));
        binding.roomTvDelete.setOnClickListener(v -> {
            if (onClickListener == null) return;
            onClickListener.clickDelete(position, item);
        });

        binding.roomIvDelete.setOnClickListener(v -> {
            //点击减号，滑出删除
            binding.slideItem.slideOut();
        });
    }

    public List<RoomSortInfoBean> getList(){
        return items;
    }

    public void onItemMove(int fromPosition, int toPosition){
        Collections.swap(items, fromPosition, toPosition);
        notifyItemMoved(fromPosition, toPosition);
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener{
        //点击删除
        void clickDelete(int position, RoomSortInfoBean roomInfo);
    }
}
